import time

from django.core.management.base import BaseCommand
from service.shedule_optimisation.optimiser import Optimiser
from service.models import Month, Event
from django.core.management import call_command
from service.fill_service_data_from_xlsx import get_data_from_xlsx
from service.prediction_service import PredictionService
from users import models
from datetime import datetime
from random import randint


class Command(BaseCommand):
    help = 'Import users from Excel file'

    def handle(self, *args, **kwargs):


        # fixture_files = [
        #     'initial_specializations_fixture.json',
        #     'initial_groups_fixture.json',
        #     'initial_users_fixture.json',
        # ]
        #
        # for fixture_file in fixture_files:
        #     self.stdout.write(f'Loading {fixture_file}')
        #     call_command('loaddata', fixture_file)
        #     self.stdout.write(self.style.SUCCESS(f'Successfully loaded {fixture_file}'))
        # get_data_from_xlsx()
        # PredictionService().predict_data()

        models.User.objects.exclude(is_superuser=True).delete()
        Event.objects.all().delete()

        for i in range(1, 300):
            user = models.User.objects.create(
                username=f'user{i}',
                password='123',
                first_name=f'first_name{i}',
                last_name=f'last_name{i}',
                main_specialization=models.Specialization.objects.get(
                    id=randint(1, len(models.Specialization.objects.all()))),

            )
            group = models.Group.objects.get(name='Врач')
            user.groups.add(group)



        month = Month.objects.get(month=2, year=2024)
        month.create_events()
        time.sleep(1)
        start_time = datetime.now()
        Optimiser(month).optimise_work()
        end_time = datetime.now()
        print('seconds', (end_time - start_time).seconds)
